import request from './request'

// 考勤数据类型
export interface AttendanceData {
  id: number
  employeeId: string
  employeeName: string
  workDays: number
  absentDays: number
  overtimeHours: number
  month: string
  remark?: string
  createTime: string
  updateTime: string
}

// 获取考勤分页
// 获取岗位分页列表
export const getAttendancePage = (params: {
  current: number
  size: number
  name?: string
  departmentId?: number
  month?: string
}) => {
  return request({
    url: '/attendance/page',
    method: 'post',
    data: params
  })
}

// 获取考勤列表
export const getAttendanceList = (params?: { month?: string; employeeName?: string }) => {
  return request({
    url: '/attendance/list',
    method: 'post',
    data: params || {}
  })
}

// 新增考勤记录
export const addAttendance = (attendance: Omit<AttendanceData, 'id' | 'createTime' | 'updateTime'>) => {
  return request({
    url: '/attendance/add',
    method: 'post',
    data: attendance
  })
}

// 编辑考勤记录
export const updateAttendance = (attendance: AttendanceData) => {
  return request({
    url: '/attendance/update',
    method: 'post',
    data: attendance
  })
}

// 删除考勤记录
export const deleteAttendance = (id: number) => {
  return request({
    url: '/attendance/delete',
    method: 'post',
    data: { id }
  })
}

// 批量导入考勤数据
export const importAttendance = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  
  return request({
    url: '/attendance/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}